<?php
namespace Home\Controller;

class ArticleController extends CommonController {
    public function index($cid = 2,$mid= 0){
        $columnlist = M('info_column')->where(array('status'=>1,'upid'=>0))->select();
        $columns = M('info_column')->where(array('status'=>1,'upid'=>$cid))->select();
        $articlelist = array();
        $pageshow = '';
        $map['status'] = 1;
        if ($mid==0) {
            foreach ($columns as $key => $value) {
                $map['column_id'] = $value['id'];
                $articles = M('info')->where($map)->order('ctime desc')->select();
                $alist = array_merge($articlelist,$articles);
                $articlelist = array_slice($alist,$Page->firstRow,$Page->listRows);
                $count = count($alist);
                $Page = new \Think\Page($count,15);
                $pageshow = $Page->show();

            }
        }else {
            $count = M('info')->where($map)->count();
            $Page = new \Think\Page($count,15);
            $pageshow = $Page->show();
            $map['column_id'] = $mid;
            $articlelist = M('info')->where($map)->order('ctime desc')->limit($Page->firstRow.','.$Page->listRows)->select();
        }
        $this->assign('cid',$cid);
        $this->assign('mid',$mid);
        $this->assign('columnlist',$columnlist);
        $this->assign('columns',$columns);
        $this->assign('articlelist',$articlelist);
        $this->assign('pageshow',$pageshow);
        $this->assign('mark','article');
        $this->display();
    }

    public function detail(){
        $id=I('param.id');
        $map['id'] = $id;
        $article = M('info')->where($map)->select();
        $this->assign('article',$article);
        $map1['id']=$id-1;
        $articlel=M('info')->where($map1)->select();
        if($articlel!=null){
            $this->assign('articlel',$articlel);
        }

        $map2['id']=$id+1;
        $articler=M('info')->where($map2)->select();
        if($articler!=null){
            $this->assign('articler',$articler);
        }

        $this->display();
    }
}
